/**
 * 角色组
 */
var RoleGroup = {};

/**
 * 载入角色组列表页面
 */
RoleGroup.loadRoleGroupList = function(){
	//$.post( Common.path + "/sysmanage/rolegroup/rolegrouplist",function(html){
	//	$("#main_right").html(html);
	//});
	$.pjax({
		url: Common.path + "/sysmanage/rolegroup/rolegrouplist",
		container: '#main_right'
	});
};

/**
 *  载入授权页面
 */
RoleGroup.openEditPermission = function( index, groupId  ){
	$("#rolegroup_datagrid").datagrid('showExtendContent_x',index);
	var div = $("#rolegroup_datagrid").datagrid('findExtendContent_x',index);
	$.post(Common.path+"/sysmanage/permission/permissionList",{"rolegroup_id":groupId, "index":index},
		function(html){
			div.html(html);
			$("#rolegroup_datagrid").datagrid('resizeExtendContent_x');
		}
	);
};

/**
 * 保存权限分配
 */
RoleGroup.savePermission = function( that ){
	var form = $(that).closest("form");
	var op = {
		url: Common.path+"/sysmanage/permission/save", dataType:"json", type:"post",
		success:function(json){
			if( json.res > 0 ){
				$.messager.alert("系统提示","分配成功","info");
			}
			$(that).linkbutton("enable");
		},
		error:function(){ $(that).linkbutton("enable"); }
	};
	 $(that).linkbutton("disable");
	form.ajaxSubmit( op );
};

/**
 *  载入角色组修改页面
 */
RoleGroup.openEdit = function( index, groupName ){
	$("#rolegroup_datagrid").datagrid('showExtendContent_x',index);
	var div = $("#rolegroup_datagrid").datagrid('findExtendContent_x',index);
	$.post(Common.path+"/sysmanage/rolegroup/preSaveRolegroup",{"rolegroup_name":groupName, "index":index},
		function(html){
			div.html(html);
			$("#rolegroup_datagrid").datagrid('resizeExtendContent_x');
		}
	);
};
/**
 * 修改角色组
 */
RoleGroup.edit = function( that ){
	var form = $(that).closest("form");
	var op = {
		url: Common.path+"/sysmanage/rolegroup/saveRolegroup", dataType:"json", type:"post",
		success:function(json){
			if( json.res > 0 ){
				$.messager.alert("系统提示","修改成功","info");
			}else if( json.res == -2 ){
				$.messager.alert("系统提示","没有权限！","warning");
			}
			$(that).linkbutton("enable");
		},
		error:function(){ $(that).linkbutton("enable"); }
	};
	$(that).linkbutton("disable");
	form.ajaxSubmit( op );
	
};

RoleGroup.closeDatagridExtend = function( that){
	var i = $(that).closest("div[datagrid-row-extendcont-index]").attr("datagrid-row-extendcont-index");
	$("#rolegroup_datagrid").datagrid("hideExtendContent_x", i);
	$("#rolegroup_datagrid").datagrid('resizeExtendContent_x');
};

//datagrid-row-extendcont-index